package com.yao.sdk.glide;

import android.content.Context;
import android.os.Environment;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.cache.DiskCache;
import com.bumptech.glide.load.engine.cache.DiskLruCacheWrapper;
import com.bumptech.glide.module.GlideModule;

import java.io.File;

/**
 * Created by Administrator on 2016/7/14.
 */
public class GlideConfiguration implements GlideModule {
    @Override
    public void applyOptions(final Context context, GlideBuilder builder) {
 //Glide 默认使用低质量的 RGB565内存占用比较少
        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
        final File cacheDir;
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
            cacheDir=context.getExternalCacheDir();
        }else {
            cacheDir=context.getCacheDir();
        }
        builder.setDiskCache(new DiskCache.Factory() {
            @Override
            public DiskCache build() {
                File cacheLocation = new File(cacheDir,"img_cache");
                cacheLocation.mkdirs();
                return DiskLruCacheWrapper.get(cacheLocation,1024 * 1024 * 200);

            }
        });
    }

    @Override
    public void registerComponents(Context context, Glide glide) {

    }
}
